﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Eco.ObjectRepresentation;
using Descriptions_DomainModel.Model;
using CommonClasses;
using System.Reflection;
using System.IO;

namespace MLS_MP11_RobotSupervisor
{
    public class MLS_MP11_RobotSupervisor  : IConnection
    {
        /// <summary>
        /// Название группы узлов, для которых предназначен супервизор
        /// </summary>
        private string name;

        private CommonCycleRobotSupervisor.CommonCycleRobotSupervisor commonCycleRobotSupervisor;

        private List<PinLogic> logics = new List<PinLogic>(); 

        public MLS_MP11_RobotSupervisor(IEcoServiceProvider serviceProvider, NodeGroup nodeGroup, IConnection connectionDispatcher)
        {
            this.name = Path.GetFileNameWithoutExtension(nodeGroup.AssemblyConfigFileName);
            this.commonCycleRobotSupervisor = new CommonCycleRobotSupervisor.CommonCycleRobotSupervisor(serviceProvider, nodeGroup, connectionDispatcher);

            connectionDispatcher.OnPinStateChanged += new PinStateChangedHandler(connectionDispatcher_OnPinStateChanged);

            XmlSerializer xmlser = new XmlSerializer(typeof(string));
            TextWriter writer = new StreamWriter("");

            TextReader reader = new StreamReader("mp11_level_logic.xml");
            string inPinsLogicString = xmlser.Deserialize(reader) as string;
            Console.WriteLine(inPinsLogicString);
            reader.Close();


            Console.WriteLine("MLS_MP11_RobotSupervisor created");
        }

        void connectionDispatcher_OnPinStateChanged(int virtualPin, int newState)
        {
            throw new NotImplementedException();
        }

        #region IConnection Members

        public event PinStateChangedHandler OnPinStateChanged;

        public void OnPin(int virtualPinOut, int signal)
        {
            commonCycleRobotSupervisor.OnPin(virtualPinOut, signal);
        }

        public void FlushPins()
        {
            commonCycleRobotSupervisor.FlushPins();
        }

        public void Dispose()
        {
            commonCycleRobotSupervisor.Dispose();
        }

        #endregion
    }
}
